package nio.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

public class NIOServerStart {
    public static void main(String[] args) throws IOException {
        // 创建选择器
        Selector selector = Selector.open();
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.configureBlocking(false);
        serverSocketChannel.socket().bind(new InetSocketAddress("127.0.0.1",16101));
        serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
        Thread thread = new Thread(new NIOServer(selector));
        thread.start();
    }
}
